<?php
if (session_id() == "") session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include_once "ewcfg10.php" ?>
<?php include_once "ewmysql10.php" ?>
<?php include_once "phpfn10.php" ?>
<?php include_once "pedidodetalleinfo.php" ?>
<?php include_once "usuariosinfo.php" ?>
<?php include_once "pedidosinfo.php" ?>
<?php include_once "userfn10.php" ?>
<?php

//
// Page class
//

$pedidodetalle_add = NULL; // Initialize page object first

class cpedidodetalle_add extends cpedidodetalle {

	// Page ID
	var $PageID = 'add';

	// Project ID
	var $ProjectID = "{F232ADC5-E4A2-4026-8F03-D0514C19EE8E}";

	// Table name
	var $TableName = 'pedidodetalle';

	// Page object name
	var $PageObjName = 'pedidodetalle_add';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		if ($this->UseTokenInUrl) $PageUrl .= "t=" . $this->TableVar . "&"; // Add page token
		return $PageUrl;
	}

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_MESSAGE], $v);
	}

	function getFailureMessage() {
		return @$_SESSION[EW_SESSION_FAILURE_MESSAGE];
	}

	function setFailureMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_FAILURE_MESSAGE], $v);
	}

	function getSuccessMessage() {
		return @$_SESSION[EW_SESSION_SUCCESS_MESSAGE];
	}

	function setSuccessMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_SUCCESS_MESSAGE], $v);
	}

	function getWarningMessage() {
		return @$_SESSION[EW_SESSION_WARNING_MESSAGE];
	}

	function setWarningMessage($v) {
		ew_AddMessage($_SESSION[EW_SESSION_WARNING_MESSAGE], $v);
	}

	// Show message
	function ShowMessage() {
		$hidden = FALSE;
		$html = "";

		// Message
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage, "");
		if ($sMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sMessage;
			$html .= "<div class=\"alert alert-success ewSuccess\">" . $sMessage . "</div>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}

		// Warning message
		$sWarningMessage = $this->getWarningMessage();
		$this->Message_Showing($sWarningMessage, "warning");
		if ($sWarningMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sWarningMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sWarningMessage;
			$html .= "<div class=\"alert alert-warning ewWarning\">" . $sWarningMessage . "</div>";
			$_SESSION[EW_SESSION_WARNING_MESSAGE] = ""; // Clear message in Session
		}

		// Success message
		$sSuccessMessage = $this->getSuccessMessage();
		$this->Message_Showing($sSuccessMessage, "success");
		if ($sSuccessMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sSuccessMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sSuccessMessage;
			$html .= "<div class=\"alert alert-success ewSuccess\">" . $sSuccessMessage . "</div>";
			$_SESSION[EW_SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session
		}

		// Failure message
		$sErrorMessage = $this->getFailureMessage();
		$this->Message_Showing($sErrorMessage, "failure");
		if ($sErrorMessage <> "") { // Message in Session, display
			if (!$hidden)
				$sErrorMessage = "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" . $sErrorMessage;
			$html .= "<div class=\"alert alert-error ewError\">" . $sErrorMessage . "</div>";
			$_SESSION[EW_SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session
		}
		echo "<table class=\"ewStdTable\"><tr><td><div class=\"ewMessageDialog\"" . (($hidden) ? " style=\"display: none;\"" : "") . ">" . $html . "</div></td></tr></table>";
	}
	var $PageHeader;
	var $PageFooter;

	// Show Page Header
	function ShowPageHeader() {
		$sHeader = $this->PageHeader;
		$this->Page_DataRendering($sHeader);
		if ($sHeader <> "") { // Header exists, display
			echo "<p>" . $sHeader . "</p>";
		}
	}

	// Show Page Footer
	function ShowPageFooter() {
		$sFooter = $this->PageFooter;
		$this->Page_DataRendered($sFooter);
		if ($sFooter <> "") { // Footer exists, display
			echo "<p>" . $sFooter . "</p>";
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm;
		if ($this->UseTokenInUrl) {
			if ($objForm)
				return ($this->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($this->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function __construct() {
		global $conn, $Language;
		$GLOBALS["Page"] = &$this;

		// Language object
		if (!isset($Language)) $Language = new cLanguage();

		// Parent constuctor
		parent::__construct();

		// Table object (pedidodetalle)
		if (!isset($GLOBALS["pedidodetalle"]) || get_class($GLOBALS["pedidodetalle"]) == "cpedidodetalle") {
			$GLOBALS["pedidodetalle"] = &$this;
			$GLOBALS["Table"] = &$GLOBALS["pedidodetalle"];
		}

		// Table object (usuarios)
		if (!isset($GLOBALS['usuarios'])) $GLOBALS['usuarios'] = new cusuarios();

		// Table object (pedidos)
		if (!isset($GLOBALS['pedidos'])) $GLOBALS['pedidos'] = new cpedidos();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'add', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'pedidodetalle', TRUE);

		// Start timer
		if (!isset($GLOBALS["gTimer"])) $GLOBALS["gTimer"] = new cTimer();

		// Open connection
		if (!isset($conn)) $conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;

		// Security
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		$Security->TablePermission_Loading();
		$Security->LoadCurrentUserLevel($this->ProjectID . $this->TableName);
		$Security->TablePermission_Loaded();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}
		if (!$Security->CanAdd()) {
			$Security->SaveLastUrl();
			$this->setFailureMessage($Language->Phrase("NoPermission")); // Set no permission
			$this->Page_Terminate("pedidodetallelist.php");
		}

		// Create form object
		$objForm = new cFormObj();
		$this->CurrentAction = (@$_GET["a"] <> "") ? $_GET["a"] : @$_POST["a_list"]; // Set up curent action

		// Global Page Loading event (in userfn*.php)
		Page_Loading();

		// Page Load event
		$this->Page_Load();
	}

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();
		$this->Page_Redirecting($url);

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}
	var $DbMasterFilter = "";
	var $DbDetailFilter = "";
	var $Priv = 0;
	var $OldRecordset;
	var $CopyRecord;

	// 
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsFormError;

		// Set up master/detail parameters
		$this->SetUpMasterParms();

		// Process form if post back
		if (@$_POST["a_add"] <> "") {
			$this->CurrentAction = $_POST["a_add"]; // Get form action
			$this->CopyRecord = $this->LoadOldRecord(); // Load old recordset
			$this->LoadFormValues(); // Load form values
		} else { // Not post back

			// Load key values from QueryString
			$this->CopyRecord = TRUE;
			if (@$_GET["detalleId"] != "") {
				$this->detalleId->setQueryStringValue($_GET["detalleId"]);
				$this->setKey("detalleId", $this->detalleId->CurrentValue); // Set up key
			} else {
				$this->setKey("detalleId", ""); // Clear key
				$this->CopyRecord = FALSE;
			}
			if ($this->CopyRecord) {
				$this->CurrentAction = "C"; // Copy record
			} else {
				$this->CurrentAction = "I"; // Display blank record
				$this->LoadDefaultValues(); // Load default values
			}
		}

		// Set up Breadcrumb
		$this->SetupBreadcrumb();

		// Validate form if post back
		if (@$_POST["a_add"] <> "") {
			if (!$this->ValidateForm()) {
				$this->CurrentAction = "I"; // Form error, reset action
				$this->EventCancelled = TRUE; // Event cancelled
				$this->RestoreFormValues(); // Restore form values
				$this->setFailureMessage($gsFormError);
			}
		}

		// Perform action based on action code
		switch ($this->CurrentAction) {
			case "I": // Blank record, no action required
				break;
			case "C": // Copy an existing record
				if (!$this->LoadRow()) { // Load record based on key
					if ($this->getFailureMessage() == "") $this->setFailureMessage($Language->Phrase("NoRecord")); // No record found
					$this->Page_Terminate("pedidodetallelist.php"); // No matching record, return to list
				}
				break;
			case "A": // Add new record
				$this->SendEmail = TRUE; // Send email on add success
				if ($this->AddRow($this->OldRecordset)) { // Add successful
					if ($this->getSuccessMessage() == "")
						$this->setSuccessMessage($Language->Phrase("AddSuccess")); // Set up success message
					$sReturnUrl = $this->getReturnUrl();
					if (ew_GetPageName($sReturnUrl) == "pedidodetalleview.php")
						$sReturnUrl = $this->GetViewUrl(); // View paging, return to view page with keyurl directly
					$this->Page_Terminate($sReturnUrl); // Clean up and return
				} else {
					$this->EventCancelled = TRUE; // Event cancelled
					$this->RestoreFormValues(); // Add failed, restore form values
				}
		}

		// Render row based on row type
		$this->RowType = EW_ROWTYPE_ADD;  // Render add type

		// Render row
		$this->ResetAttrs();
		$this->RenderRow();
	}

	// Get upload files
	function GetUploadFiles() {
		global $objForm;

		// Get upload data
	}

	// Load default values
	function LoadDefaultValues() {
		$this->detallePedido->CurrentValue = NULL;
		$this->detallePedido->OldValue = $this->detallePedido->CurrentValue;
		$this->detalleItem->CurrentValue = NULL;
		$this->detalleItem->OldValue = $this->detalleItem->CurrentValue;
		$this->detalleProducto->CurrentValue = NULL;
		$this->detalleProducto->OldValue = $this->detalleProducto->CurrentValue;
		$this->detalleEstadoProducto->CurrentValue = NULL;
		$this->detalleEstadoProducto->OldValue = $this->detalleEstadoProducto->CurrentValue;
		$this->detalleUnidades->CurrentValue = NULL;
		$this->detalleUnidades->OldValue = $this->detalleUnidades->CurrentValue;
		$this->detalleMetros->CurrentValue = NULL;
		$this->detalleMetros->OldValue = $this->detalleMetros->CurrentValue;
		$this->detallePallets->CurrentValue = NULL;
		$this->detallePallets->OldValue = $this->detallePallets->CurrentValue;
		$this->detallePaquetes->CurrentValue = NULL;
		$this->detallePaquetes->OldValue = $this->detallePaquetes->CurrentValue;
		$this->detallePreparado->CurrentValue = NULL;
		$this->detallePreparado->OldValue = $this->detallePreparado->CurrentValue;
		$this->detalleMotivo->CurrentValue = NULL;
		$this->detalleMotivo->OldValue = $this->detalleMotivo->CurrentValue;
		$this->detalleTipo->CurrentValue = NULL;
		$this->detalleTipo->OldValue = $this->detalleTipo->CurrentValue;
		$this->detallePunto->CurrentValue = NULL;
		$this->detallePunto->OldValue = $this->detallePunto->CurrentValue;
		$this->detalleNumero->CurrentValue = NULL;
		$this->detalleNumero->OldValue = $this->detalleNumero->CurrentValue;
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm;
		if (!$this->detallePedido->FldIsDetailKey) {
			$this->detallePedido->setFormValue($objForm->GetValue("x_detallePedido"));
		}
		if (!$this->detalleItem->FldIsDetailKey) {
			$this->detalleItem->setFormValue($objForm->GetValue("x_detalleItem"));
		}
		if (!$this->detalleProducto->FldIsDetailKey) {
			$this->detalleProducto->setFormValue($objForm->GetValue("x_detalleProducto"));
		}
		if (!$this->detalleEstadoProducto->FldIsDetailKey) {
			$this->detalleEstadoProducto->setFormValue($objForm->GetValue("x_detalleEstadoProducto"));
		}
		if (!$this->detalleUnidades->FldIsDetailKey) {
			$this->detalleUnidades->setFormValue($objForm->GetValue("x_detalleUnidades"));
		}
		if (!$this->detalleMetros->FldIsDetailKey) {
			$this->detalleMetros->setFormValue($objForm->GetValue("x_detalleMetros"));
		}
		if (!$this->detallePallets->FldIsDetailKey) {
			$this->detallePallets->setFormValue($objForm->GetValue("x_detallePallets"));
		}
		if (!$this->detallePaquetes->FldIsDetailKey) {
			$this->detallePaquetes->setFormValue($objForm->GetValue("x_detallePaquetes"));
		}
		if (!$this->detallePreparado->FldIsDetailKey) {
			$this->detallePreparado->setFormValue($objForm->GetValue("x_detallePreparado"));
		}
		if (!$this->detalleMotivo->FldIsDetailKey) {
			$this->detalleMotivo->setFormValue($objForm->GetValue("x_detalleMotivo"));
		}
		if (!$this->detalleTipo->FldIsDetailKey) {
			$this->detalleTipo->setFormValue($objForm->GetValue("x_detalleTipo"));
		}
		if (!$this->detallePunto->FldIsDetailKey) {
			$this->detallePunto->setFormValue($objForm->GetValue("x_detallePunto"));
		}
		if (!$this->detalleNumero->FldIsDetailKey) {
			$this->detalleNumero->setFormValue($objForm->GetValue("x_detalleNumero"));
		}
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm;
		$this->LoadOldRecord();
		$this->detallePedido->CurrentValue = $this->detallePedido->FormValue;
		$this->detalleItem->CurrentValue = $this->detalleItem->FormValue;
		$this->detalleProducto->CurrentValue = $this->detalleProducto->FormValue;
		$this->detalleEstadoProducto->CurrentValue = $this->detalleEstadoProducto->FormValue;
		$this->detalleUnidades->CurrentValue = $this->detalleUnidades->FormValue;
		$this->detalleMetros->CurrentValue = $this->detalleMetros->FormValue;
		$this->detallePallets->CurrentValue = $this->detallePallets->FormValue;
		$this->detallePaquetes->CurrentValue = $this->detallePaquetes->FormValue;
		$this->detallePreparado->CurrentValue = $this->detallePreparado->FormValue;
		$this->detalleMotivo->CurrentValue = $this->detalleMotivo->FormValue;
		$this->detalleTipo->CurrentValue = $this->detalleTipo->FormValue;
		$this->detallePunto->CurrentValue = $this->detallePunto->FormValue;
		$this->detalleNumero->CurrentValue = $this->detalleNumero->FormValue;
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $Language;
		$sFilter = $this->KeyFilter();

		// Call Row Selecting event
		$this->Row_Selecting($sFilter);

		// Load SQL based on filter
		$this->CurrentFilter = $sFilter;
		$sSql = $this->SQL();
		$res = FALSE;
		$rs = ew_LoadRecordset($sSql);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->LoadRowValues($rs); // Load row values
			$rs->Close();
		}
		return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn;
		if (!$rs || $rs->EOF) return;

		// Call Row Selected event
		$row = &$rs->fields;
		$this->Row_Selected($row);
		$this->detalleId->setDbValue($rs->fields('detalleId'));
		$this->detallePedido->setDbValue($rs->fields('detallePedido'));
		$this->detalleItem->setDbValue($rs->fields('detalleItem'));
		$this->detalleProducto->setDbValue($rs->fields('detalleProducto'));
		$this->detalleEstadoProducto->setDbValue($rs->fields('detalleEstadoProducto'));
		$this->detalleUnidades->setDbValue($rs->fields('detalleUnidades'));
		$this->detalleMetros->setDbValue($rs->fields('detalleMetros'));
		$this->detallePallets->setDbValue($rs->fields('detallePallets'));
		$this->detallePaquetes->setDbValue($rs->fields('detallePaquetes'));
		$this->detallePreparado->setDbValue($rs->fields('detallePreparado'));
		$this->detalleMotivo->setDbValue($rs->fields('detalleMotivo'));
		$this->detalleTipo->setDbValue($rs->fields('detalleTipo'));
		$this->detallePunto->setDbValue($rs->fields('detallePunto'));
		$this->detalleNumero->setDbValue($rs->fields('detalleNumero'));
	}

	// Load DbValue from recordset
	function LoadDbValues(&$rs) {
		if (!$rs || !is_array($rs) && $rs->EOF) return;
		$row = is_array($rs) ? $rs : $rs->fields;
		$this->detalleId->DbValue = $row['detalleId'];
		$this->detallePedido->DbValue = $row['detallePedido'];
		$this->detalleItem->DbValue = $row['detalleItem'];
		$this->detalleProducto->DbValue = $row['detalleProducto'];
		$this->detalleEstadoProducto->DbValue = $row['detalleEstadoProducto'];
		$this->detalleUnidades->DbValue = $row['detalleUnidades'];
		$this->detalleMetros->DbValue = $row['detalleMetros'];
		$this->detallePallets->DbValue = $row['detallePallets'];
		$this->detallePaquetes->DbValue = $row['detallePaquetes'];
		$this->detallePreparado->DbValue = $row['detallePreparado'];
		$this->detalleMotivo->DbValue = $row['detalleMotivo'];
		$this->detalleTipo->DbValue = $row['detalleTipo'];
		$this->detallePunto->DbValue = $row['detallePunto'];
		$this->detalleNumero->DbValue = $row['detalleNumero'];
	}

	// Load old record
	function LoadOldRecord() {

		// Load key values from Session
		$bValidKey = TRUE;
		if (strval($this->getKey("detalleId")) <> "")
			$this->detalleId->CurrentValue = $this->getKey("detalleId"); // detalleId
		else
			$bValidKey = FALSE;

		// Load old recordset
		if ($bValidKey) {
			$this->CurrentFilter = $this->KeyFilter();
			$sSql = $this->SQL();
			$this->OldRecordset = ew_LoadRecordset($sSql);
			$this->LoadRowValues($this->OldRecordset); // Load row values
		} else {
			$this->OldRecordset = NULL;
		}
		return $bValidKey;
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $Language;
		global $gsLanguage;

		// Initialize URLs
		// Convert decimal values if posted back

		if ($this->detalleMetros->FormValue == $this->detalleMetros->CurrentValue && is_numeric(ew_StrToFloat($this->detalleMetros->CurrentValue)))
			$this->detalleMetros->CurrentValue = ew_StrToFloat($this->detalleMetros->CurrentValue);

		// Call Row_Rendering event
		$this->Row_Rendering();

		// Common render codes for all row types
		// detalleId
		// detallePedido
		// detalleItem
		// detalleProducto
		// detalleEstadoProducto
		// detalleUnidades
		// detalleMetros
		// detallePallets
		// detallePaquetes
		// detallePreparado
		// detalleMotivo
		// detalleTipo
		// detallePunto
		// detalleNumero

		if ($this->RowType == EW_ROWTYPE_VIEW) { // View row

			// detalleId
			$this->detalleId->ViewValue = $this->detalleId->CurrentValue;
			$this->detalleId->ViewCustomAttributes = "";

			// detallePedido
			$this->detallePedido->ViewValue = $this->detallePedido->CurrentValue;
			$this->detallePedido->ViewCustomAttributes = "";

			// detalleItem
			$this->detalleItem->ViewValue = $this->detalleItem->CurrentValue;
			$this->detalleItem->ViewCustomAttributes = "";

			// detalleProducto
			if (strval($this->detalleProducto->CurrentValue) <> "") {
				$sFilterWrk = "`productosCodigo`" . ew_SearchString("=", $this->detalleProducto->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `productosCodigo`, `productosCodigo` AS `DispFld`, `productosNombre` AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `productos`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->detalleProducto, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->detalleProducto->ViewValue = $rswrk->fields('DispFld');
					$this->detalleProducto->ViewValue .= ew_ValueSeparator(1,$this->detalleProducto) . $rswrk->fields('Disp2Fld');
					$rswrk->Close();
				} else {
					$this->detalleProducto->ViewValue = $this->detalleProducto->CurrentValue;
				}
			} else {
				$this->detalleProducto->ViewValue = NULL;
			}
			$this->detalleProducto->ViewCustomAttributes = "";

			// detalleEstadoProducto
			if (strval($this->detalleEstadoProducto->CurrentValue) <> "") {
				switch ($this->detalleEstadoProducto->CurrentValue) {
					case $this->detalleEstadoProducto->FldTagValue(1):
						$this->detalleEstadoProducto->ViewValue = $this->detalleEstadoProducto->FldTagCaption(1) <> "" ? $this->detalleEstadoProducto->FldTagCaption(1) : $this->detalleEstadoProducto->CurrentValue;
						break;
					case $this->detalleEstadoProducto->FldTagValue(2):
						$this->detalleEstadoProducto->ViewValue = $this->detalleEstadoProducto->FldTagCaption(2) <> "" ? $this->detalleEstadoProducto->FldTagCaption(2) : $this->detalleEstadoProducto->CurrentValue;
						break;
					case $this->detalleEstadoProducto->FldTagValue(3):
						$this->detalleEstadoProducto->ViewValue = $this->detalleEstadoProducto->FldTagCaption(3) <> "" ? $this->detalleEstadoProducto->FldTagCaption(3) : $this->detalleEstadoProducto->CurrentValue;
						break;
					case $this->detalleEstadoProducto->FldTagValue(4):
						$this->detalleEstadoProducto->ViewValue = $this->detalleEstadoProducto->FldTagCaption(4) <> "" ? $this->detalleEstadoProducto->FldTagCaption(4) : $this->detalleEstadoProducto->CurrentValue;
						break;
					case $this->detalleEstadoProducto->FldTagValue(5):
						$this->detalleEstadoProducto->ViewValue = $this->detalleEstadoProducto->FldTagCaption(5) <> "" ? $this->detalleEstadoProducto->FldTagCaption(5) : $this->detalleEstadoProducto->CurrentValue;
						break;
					default:
						$this->detalleEstadoProducto->ViewValue = $this->detalleEstadoProducto->CurrentValue;
				}
			} else {
				$this->detalleEstadoProducto->ViewValue = NULL;
			}
			$this->detalleEstadoProducto->ViewCustomAttributes = "";

			// detalleUnidades
			$this->detalleUnidades->ViewValue = $this->detalleUnidades->CurrentValue;
			$this->detalleUnidades->ViewCustomAttributes = "";

			// detalleMetros
			$this->detalleMetros->ViewValue = $this->detalleMetros->CurrentValue;
			$this->detalleMetros->ViewCustomAttributes = "";

			// detallePallets
			$this->detallePallets->ViewValue = $this->detallePallets->CurrentValue;
			$this->detallePallets->ViewCustomAttributes = "";

			// detallePaquetes
			$this->detallePaquetes->ViewValue = $this->detallePaquetes->CurrentValue;
			$this->detallePaquetes->ViewCustomAttributes = "";

			// detallePreparado
			$this->detallePreparado->ViewValue = $this->detallePreparado->CurrentValue;
			$this->detallePreparado->ViewCustomAttributes = "";

			// detalleMotivo
			if (strval($this->detalleMotivo->CurrentValue) <> "") {
				$sFilterWrk = "`motivoId`" . ew_SearchString("=", $this->detalleMotivo->CurrentValue, EW_DATATYPE_NUMBER);
			$sSqlWrk = "SELECT `motivoId`, `motivoNombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `motivos`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->detalleMotivo, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$this->detalleMotivo->ViewValue = $rswrk->fields('DispFld');
					$rswrk->Close();
				} else {
					$this->detalleMotivo->ViewValue = $this->detalleMotivo->CurrentValue;
				}
			} else {
				$this->detalleMotivo->ViewValue = NULL;
			}
			$this->detalleMotivo->ViewCustomAttributes = "";

			// detalleTipo
			$this->detalleTipo->ViewValue = $this->detalleTipo->CurrentValue;
			$this->detalleTipo->ViewCustomAttributes = "";

			// detallePunto
			$this->detallePunto->ViewValue = $this->detallePunto->CurrentValue;
			$this->detallePunto->ViewCustomAttributes = "";

			// detalleNumero
			$this->detalleNumero->ViewValue = $this->detalleNumero->CurrentValue;
			$this->detalleNumero->ViewCustomAttributes = "";

			// detallePedido
			$this->detallePedido->LinkCustomAttributes = "";
			$this->detallePedido->HrefValue = "";
			$this->detallePedido->TooltipValue = "";

			// detalleItem
			$this->detalleItem->LinkCustomAttributes = "";
			$this->detalleItem->HrefValue = "";
			$this->detalleItem->TooltipValue = "";

			// detalleProducto
			$this->detalleProducto->LinkCustomAttributes = "";
			$this->detalleProducto->HrefValue = "";
			$this->detalleProducto->TooltipValue = "";

			// detalleEstadoProducto
			$this->detalleEstadoProducto->LinkCustomAttributes = "";
			$this->detalleEstadoProducto->HrefValue = "";
			$this->detalleEstadoProducto->TooltipValue = "";

			// detalleUnidades
			$this->detalleUnidades->LinkCustomAttributes = "";
			$this->detalleUnidades->HrefValue = "";
			$this->detalleUnidades->TooltipValue = "";

			// detalleMetros
			$this->detalleMetros->LinkCustomAttributes = "";
			$this->detalleMetros->HrefValue = "";
			$this->detalleMetros->TooltipValue = "";

			// detallePallets
			$this->detallePallets->LinkCustomAttributes = "";
			$this->detallePallets->HrefValue = "";
			$this->detallePallets->TooltipValue = "";

			// detallePaquetes
			$this->detallePaquetes->LinkCustomAttributes = "";
			$this->detallePaquetes->HrefValue = "";
			$this->detallePaquetes->TooltipValue = "";

			// detallePreparado
			$this->detallePreparado->LinkCustomAttributes = "";
			$this->detallePreparado->HrefValue = "";
			$this->detallePreparado->TooltipValue = "";

			// detalleMotivo
			$this->detalleMotivo->LinkCustomAttributes = "";
			$this->detalleMotivo->HrefValue = "";
			$this->detalleMotivo->TooltipValue = "";

			// detalleTipo
			$this->detalleTipo->LinkCustomAttributes = "";
			$this->detalleTipo->HrefValue = "";
			$this->detalleTipo->TooltipValue = "";

			// detallePunto
			$this->detallePunto->LinkCustomAttributes = "";
			$this->detallePunto->HrefValue = "";
			$this->detallePunto->TooltipValue = "";

			// detalleNumero
			$this->detalleNumero->LinkCustomAttributes = "";
			$this->detalleNumero->HrefValue = "";
			$this->detalleNumero->TooltipValue = "";
		} elseif ($this->RowType == EW_ROWTYPE_ADD) { // Add row

			// detallePedido
			$this->detallePedido->EditCustomAttributes = "";
			if ($this->detallePedido->getSessionValue() <> "") {
				$this->detallePedido->CurrentValue = $this->detallePedido->getSessionValue();
			$this->detallePedido->ViewValue = $this->detallePedido->CurrentValue;
			$this->detallePedido->ViewCustomAttributes = "";
			} else {
			$this->detallePedido->EditValue = ew_HtmlEncode($this->detallePedido->CurrentValue);
			$this->detallePedido->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->detallePedido->FldCaption()));
			}

			// detalleItem
			$this->detalleItem->EditCustomAttributes = "";
			$this->detalleItem->EditValue = ew_HtmlEncode($this->detalleItem->CurrentValue);
			$this->detalleItem->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->detalleItem->FldCaption()));

			// detalleProducto
			$this->detalleProducto->EditCustomAttributes = "";
			if (trim(strval($this->detalleProducto->CurrentValue)) == "") {
				$sFilterWrk = "0=1";
			} else {
				$sFilterWrk = "`productosCodigo`" . ew_SearchString("=", $this->detalleProducto->CurrentValue, EW_DATATYPE_NUMBER);
			}
			$sSqlWrk = "SELECT `productosCodigo`, `productosCodigo` AS `DispFld`, `productosNombre` AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `productos`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->detalleProducto, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->detalleProducto->EditValue = $arwrk;

			// detalleEstadoProducto
			$this->detalleEstadoProducto->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array($this->detalleEstadoProducto->FldTagValue(1), $this->detalleEstadoProducto->FldTagCaption(1) <> "" ? $this->detalleEstadoProducto->FldTagCaption(1) : $this->detalleEstadoProducto->FldTagValue(1));
			$arwrk[] = array($this->detalleEstadoProducto->FldTagValue(2), $this->detalleEstadoProducto->FldTagCaption(2) <> "" ? $this->detalleEstadoProducto->FldTagCaption(2) : $this->detalleEstadoProducto->FldTagValue(2));
			$arwrk[] = array($this->detalleEstadoProducto->FldTagValue(3), $this->detalleEstadoProducto->FldTagCaption(3) <> "" ? $this->detalleEstadoProducto->FldTagCaption(3) : $this->detalleEstadoProducto->FldTagValue(3));
			$arwrk[] = array($this->detalleEstadoProducto->FldTagValue(4), $this->detalleEstadoProducto->FldTagCaption(4) <> "" ? $this->detalleEstadoProducto->FldTagCaption(4) : $this->detalleEstadoProducto->FldTagValue(4));
			$arwrk[] = array($this->detalleEstadoProducto->FldTagValue(5), $this->detalleEstadoProducto->FldTagCaption(5) <> "" ? $this->detalleEstadoProducto->FldTagCaption(5) : $this->detalleEstadoProducto->FldTagValue(5));
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$this->detalleEstadoProducto->EditValue = $arwrk;

			// detalleUnidades
			$this->detalleUnidades->EditCustomAttributes = "";
			$this->detalleUnidades->EditValue = ew_HtmlEncode($this->detalleUnidades->CurrentValue);
			$this->detalleUnidades->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->detalleUnidades->FldCaption()));

			// detalleMetros
			$this->detalleMetros->EditCustomAttributes = "";
			$this->detalleMetros->EditValue = ew_HtmlEncode($this->detalleMetros->CurrentValue);
			$this->detalleMetros->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->detalleMetros->FldCaption()));
			if (strval($this->detalleMetros->EditValue) <> "" && is_numeric($this->detalleMetros->EditValue)) $this->detalleMetros->EditValue = ew_FormatNumber($this->detalleMetros->EditValue, -2, -1, -2, 0);

			// detallePallets
			$this->detallePallets->EditCustomAttributes = "";
			$this->detallePallets->EditValue = ew_HtmlEncode($this->detallePallets->CurrentValue);
			$this->detallePallets->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->detallePallets->FldCaption()));

			// detallePaquetes
			$this->detallePaquetes->EditCustomAttributes = "";
			$this->detallePaquetes->EditValue = ew_HtmlEncode($this->detallePaquetes->CurrentValue);
			$this->detallePaquetes->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->detallePaquetes->FldCaption()));

			// detallePreparado
			$this->detallePreparado->EditCustomAttributes = "";
			$this->detallePreparado->EditValue = ew_HtmlEncode($this->detallePreparado->CurrentValue);
			$this->detallePreparado->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->detallePreparado->FldCaption()));

			// detalleMotivo
			$this->detalleMotivo->EditCustomAttributes = "";
			if (trim(strval($this->detalleMotivo->CurrentValue)) == "") {
				$sFilterWrk = "0=1";
			} else {
				$sFilterWrk = "`motivoId`" . ew_SearchString("=", $this->detalleMotivo->CurrentValue, EW_DATATYPE_NUMBER);
			}
			$sSqlWrk = "SELECT `motivoId`, `motivoNombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld`, '' AS `SelectFilterFld`, '' AS `SelectFilterFld2`, '' AS `SelectFilterFld3`, '' AS `SelectFilterFld4` FROM `motivos`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				ew_AddFilter($sWhereWrk, $sFilterWrk);
			}

			// Call Lookup selecting
			$this->Lookup_Selecting($this->detalleMotivo, $sWhereWrk);
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect"), "", "", "", "", "", "", ""));
			$this->detalleMotivo->EditValue = $arwrk;

			// detalleTipo
			$this->detalleTipo->EditCustomAttributes = "";
			$this->detalleTipo->EditValue = ew_HtmlEncode($this->detalleTipo->CurrentValue);
			$this->detalleTipo->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->detalleTipo->FldCaption()));

			// detallePunto
			$this->detallePunto->EditCustomAttributes = "";
			$this->detallePunto->EditValue = ew_HtmlEncode($this->detallePunto->CurrentValue);
			$this->detallePunto->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->detallePunto->FldCaption()));

			// detalleNumero
			$this->detalleNumero->EditCustomAttributes = "";
			$this->detalleNumero->EditValue = ew_HtmlEncode($this->detalleNumero->CurrentValue);
			$this->detalleNumero->PlaceHolder = ew_HtmlEncode(ew_RemoveHtml($this->detalleNumero->FldCaption()));

			// Edit refer script
			// detallePedido

			$this->detallePedido->HrefValue = "";

			// detalleItem
			$this->detalleItem->HrefValue = "";

			// detalleProducto
			$this->detalleProducto->HrefValue = "";

			// detalleEstadoProducto
			$this->detalleEstadoProducto->HrefValue = "";

			// detalleUnidades
			$this->detalleUnidades->HrefValue = "";

			// detalleMetros
			$this->detalleMetros->HrefValue = "";

			// detallePallets
			$this->detallePallets->HrefValue = "";

			// detallePaquetes
			$this->detallePaquetes->HrefValue = "";

			// detallePreparado
			$this->detallePreparado->HrefValue = "";

			// detalleMotivo
			$this->detalleMotivo->HrefValue = "";

			// detalleTipo
			$this->detalleTipo->HrefValue = "";

			// detallePunto
			$this->detallePunto->HrefValue = "";

			// detalleNumero
			$this->detalleNumero->HrefValue = "";
		}
		if ($this->RowType == EW_ROWTYPE_ADD ||
			$this->RowType == EW_ROWTYPE_EDIT ||
			$this->RowType == EW_ROWTYPE_SEARCH) { // Add / Edit / Search row
			$this->SetupFieldTitles();
		}

		// Call Row Rendered event
		if ($this->RowType <> EW_ROWTYPE_AGGREGATEINIT)
			$this->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
		global $Language, $gsFormError;

		// Initialize form error message
		$gsFormError = "";

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if (!ew_CheckInteger($this->detallePedido->FormValue)) {
			ew_AddMessage($gsFormError, $this->detallePedido->FldErrMsg());
		}
		if (!ew_CheckInteger($this->detalleItem->FormValue)) {
			ew_AddMessage($gsFormError, $this->detalleItem->FldErrMsg());
		}
		if (!ew_CheckInteger($this->detalleUnidades->FormValue)) {
			ew_AddMessage($gsFormError, $this->detalleUnidades->FldErrMsg());
		}
		if (!ew_CheckNumber($this->detalleMetros->FormValue)) {
			ew_AddMessage($gsFormError, $this->detalleMetros->FldErrMsg());
		}
		if (!ew_CheckInteger($this->detallePallets->FormValue)) {
			ew_AddMessage($gsFormError, $this->detallePallets->FldErrMsg());
		}
		if (!ew_CheckInteger($this->detallePaquetes->FormValue)) {
			ew_AddMessage($gsFormError, $this->detallePaquetes->FldErrMsg());
		}
		if (!ew_CheckInteger($this->detallePreparado->FormValue)) {
			ew_AddMessage($gsFormError, $this->detallePreparado->FldErrMsg());
		}
		if (!ew_CheckInteger($this->detallePunto->FormValue)) {
			ew_AddMessage($gsFormError, $this->detallePunto->FldErrMsg());
		}
		if (!ew_CheckInteger($this->detalleNumero->FormValue)) {
			ew_AddMessage($gsFormError, $this->detalleNumero->FldErrMsg());
		}

		// Return validate result
		$ValidateForm = ($gsFormError == "");

		// Call Form_CustomValidate event
		$sFormCustomError = "";
		$ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
		if ($sFormCustomError <> "") {
			ew_AddMessage($gsFormError, $sFormCustomError);
		}
		return $ValidateForm;
	}

	// Add record
	function AddRow($rsold = NULL) {
		global $conn, $Language, $Security;

		// Load db values from rsold
		if ($rsold) {
			$this->LoadDbValues($rsold);
		}
		$rsnew = array();

		// detallePedido
		$this->detallePedido->SetDbValueDef($rsnew, $this->detallePedido->CurrentValue, NULL, FALSE);

		// detalleItem
		$this->detalleItem->SetDbValueDef($rsnew, $this->detalleItem->CurrentValue, NULL, FALSE);

		// detalleProducto
		$this->detalleProducto->SetDbValueDef($rsnew, $this->detalleProducto->CurrentValue, NULL, FALSE);

		// detalleEstadoProducto
		$this->detalleEstadoProducto->SetDbValueDef($rsnew, $this->detalleEstadoProducto->CurrentValue, NULL, FALSE);

		// detalleUnidades
		$this->detalleUnidades->SetDbValueDef($rsnew, $this->detalleUnidades->CurrentValue, NULL, FALSE);

		// detalleMetros
		$this->detalleMetros->SetDbValueDef($rsnew, $this->detalleMetros->CurrentValue, NULL, FALSE);

		// detallePallets
		$this->detallePallets->SetDbValueDef($rsnew, $this->detallePallets->CurrentValue, NULL, FALSE);

		// detallePaquetes
		$this->detallePaquetes->SetDbValueDef($rsnew, $this->detallePaquetes->CurrentValue, NULL, FALSE);

		// detallePreparado
		$this->detallePreparado->SetDbValueDef($rsnew, $this->detallePreparado->CurrentValue, NULL, FALSE);

		// detalleMotivo
		$this->detalleMotivo->SetDbValueDef($rsnew, $this->detalleMotivo->CurrentValue, NULL, FALSE);

		// detalleTipo
		$this->detalleTipo->SetDbValueDef($rsnew, $this->detalleTipo->CurrentValue, NULL, FALSE);

		// detallePunto
		$this->detallePunto->SetDbValueDef($rsnew, $this->detallePunto->CurrentValue, NULL, FALSE);

		// detalleNumero
		$this->detalleNumero->SetDbValueDef($rsnew, $this->detalleNumero->CurrentValue, NULL, FALSE);

		// Call Row Inserting event
		$rs = ($rsold == NULL) ? NULL : $rsold->fields;
		$bInsertRow = $this->Row_Inserting($rs, $rsnew);
		if ($bInsertRow) {
			$conn->raiseErrorFn = 'ew_ErrorFn';
			$AddRow = $this->Insert($rsnew);
			$conn->raiseErrorFn = '';
			if ($AddRow) {
			}
		} else {
			if ($this->getSuccessMessage() <> "" || $this->getFailureMessage() <> "") {

				// Use the message, do nothing
			} elseif ($this->CancelMessage <> "") {
				$this->setFailureMessage($this->CancelMessage);
				$this->CancelMessage = "";
			} else {
				$this->setFailureMessage($Language->Phrase("InsertCancelled"));
			}
			$AddRow = FALSE;
		}

		// Get insert id if necessary
		if ($AddRow) {
			$this->detalleId->setDbValue($conn->Insert_ID());
			$rsnew['detalleId'] = $this->detalleId->DbValue;
		}
		if ($AddRow) {

			// Call Row Inserted event
			$rs = ($rsold == NULL) ? NULL : $rsold->fields;
			$this->Row_Inserted($rs, $rsnew);
		}
		return $AddRow;
	}

	// Set up master/detail based on QueryString
	function SetUpMasterParms() {
		$bValidMaster = FALSE;

		// Get the keys for master table
		if (isset($_GET[EW_TABLE_SHOW_MASTER])) {
			$sMasterTblVar = $_GET[EW_TABLE_SHOW_MASTER];
			if ($sMasterTblVar == "") {
				$bValidMaster = TRUE;
				$this->DbMasterFilter = "";
				$this->DbDetailFilter = "";
			}
			if ($sMasterTblVar == "pedidos") {
				$bValidMaster = TRUE;
				if (@$_GET["pedidoID"] <> "") {
					$GLOBALS["pedidos"]->pedidoID->setQueryStringValue($_GET["pedidoID"]);
					$this->detallePedido->setQueryStringValue($GLOBALS["pedidos"]->pedidoID->QueryStringValue);
					$this->detallePedido->setSessionValue($this->detallePedido->QueryStringValue);
					if (!is_numeric($GLOBALS["pedidos"]->pedidoID->QueryStringValue)) $bValidMaster = FALSE;
				} else {
					$bValidMaster = FALSE;
				}
			}
		}
		if ($bValidMaster) {

			// Save current master table
			$this->setCurrentMasterTable($sMasterTblVar);

			// Reset start record counter (new master key)
			$this->StartRec = 1;
			$this->setStartRecordNumber($this->StartRec);

			// Clear previous master key from Session
			if ($sMasterTblVar <> "pedidos") {
				if ($this->detallePedido->QueryStringValue == "") $this->detallePedido->setSessionValue("");
			}
		}
		$this->DbMasterFilter = $this->GetMasterFilter(); //  Get master filter
		$this->DbDetailFilter = $this->GetDetailFilter(); // Get detail filter
	}

	// Set up Breadcrumb
	function SetupBreadcrumb() {
		global $Breadcrumb, $Language;
		$Breadcrumb = new cBreadcrumb();
		$Breadcrumb->Add("list", $this->TableVar, "pedidodetallelist.php", $this->TableVar, TRUE);
		$PageId = ($this->CurrentAction == "C") ? "Copy" : "Add";
		$Breadcrumb->Add("add", $PageId, ew_CurrentUrl());
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

		// Example:
		//$url = "your URL";

	}

	// Message Showing event
	// $type = ''|'success'|'failure'|'warning'
	function Message_Showing(&$msg, $type) {
		if ($type == 'success') {

			//$msg = "your success message";
		} elseif ($type == 'failure') {

			//$msg = "your failure message";
		} elseif ($type == 'warning') {

			//$msg = "your warning message";
		} else {

			//$msg = "your message";
		}
	}

	// Page Render event
	function Page_Render() {

		//echo "Page Render";
	}

	// Page Data Rendering event
	function Page_DataRendering(&$header) {

		// Example:
		//$header = "your header";

	}

	// Page Data Rendered event
	function Page_DataRendered(&$footer) {

		// Example:
		//$footer = "your footer";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

		// Return error message in CustomError
		return TRUE;
	}
}
?>
<?php ew_Header(FALSE) ?>
<?php

// Create page object
if (!isset($pedidodetalle_add)) $pedidodetalle_add = new cpedidodetalle_add();

// Page init
$pedidodetalle_add->Page_Init();

// Page main
$pedidodetalle_add->Page_Main();

// Global Page Rendering event (in userfn*.php)
Page_Rendering();

// Page Rendering event
$pedidodetalle_add->Page_Render();
?>
<?php include_once "header.php" ?>
<script type="text/javascript">

// Page object
var pedidodetalle_add = new ew_Page("pedidodetalle_add");
pedidodetalle_add.PageID = "add"; // Page ID
var EW_PAGE_ID = pedidodetalle_add.PageID; // For backward compatibility

// Form object
var fpedidodetalleadd = new ew_Form("fpedidodetalleadd");

// Validate form
fpedidodetalleadd.Validate = function() {
	if (!this.ValidateRequired)
		return true; // Ignore validation
	var $ = jQuery, fobj = this.GetForm(), $fobj = $(fobj);
	this.PostAutoSuggest();
	if ($fobj.find("#a_confirm").val() == "F")
		return true;
	var elm, felm, uelm, addcnt = 0;
	var $k = $fobj.find("#" + this.FormKeyCountName); // Get key_count
	var rowcnt = ($k[0]) ? parseInt($k.val(), 10) : 1;
	var startcnt = (rowcnt == 0) ? 0 : 1; // Check rowcnt == 0 => Inline-Add
	var gridinsert = $fobj.find("#a_list").val() == "gridinsert";
	for (var i = startcnt; i <= rowcnt; i++) {
		var infix = ($k[0]) ? String(i) : "";
		$fobj.data("rowindex", infix);
			elm = this.GetElements("x" + infix + "_detallePedido");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($pedidodetalle->detallePedido->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_detalleItem");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($pedidodetalle->detalleItem->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_detalleUnidades");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($pedidodetalle->detalleUnidades->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_detalleMetros");
			if (elm && !ew_CheckNumber(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($pedidodetalle->detalleMetros->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_detallePallets");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($pedidodetalle->detallePallets->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_detallePaquetes");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($pedidodetalle->detallePaquetes->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_detallePreparado");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($pedidodetalle->detallePreparado->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_detallePunto");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($pedidodetalle->detallePunto->FldErrMsg()) ?>");
			elm = this.GetElements("x" + infix + "_detalleNumero");
			if (elm && !ew_CheckInteger(elm.value))
				return this.OnError(elm, "<?php echo ew_JsEncode2($pedidodetalle->detalleNumero->FldErrMsg()) ?>");

			// Set up row object
			ew_ElementsToRow(fobj);

			// Fire Form_CustomValidate event
			if (!this.Form_CustomValidate(fobj))
				return false;
	}

	// Process detail forms
	var dfs = $fobj.find("input[name='detailpage']").get();
	for (var i = 0; i < dfs.length; i++) {
		var df = dfs[i], val = df.value;
		if (val && ewForms[val])
			if (!ewForms[val].Validate())
				return false;
	}
	return true;
}

// Form_CustomValidate event
fpedidodetalleadd.Form_CustomValidate = 
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }

// Use JavaScript validation or not
<?php if (EW_CLIENT_VALIDATE) { ?>
fpedidodetalleadd.ValidateRequired = true;
<?php } else { ?>
fpedidodetalleadd.ValidateRequired = false; 
<?php } ?>

// Dynamic selection lists
fpedidodetalleadd.Lists["x_detalleProducto"] = {"LinkField":"x_productosCodigo","Ajax":true,"AutoFill":false,"DisplayFields":["x_productosCodigo","x_productosNombre","",""],"ParentFields":[],"FilterFields":[],"Options":[]};
fpedidodetalleadd.Lists["x_detalleMotivo"] = {"LinkField":"x_motivoId","Ajax":true,"AutoFill":false,"DisplayFields":["x_motivoNombre","","",""],"ParentFields":[],"FilterFields":[],"Options":[]};

// Form object for search
</script>
<script type="text/javascript">

// Write your client script here, no need to add script tags.
</script>
<?php $Breadcrumb->Render(); ?>
<?php $pedidodetalle_add->ShowPageHeader(); ?>
<?php
$pedidodetalle_add->ShowMessage();
?>
<form name="fpedidodetalleadd" id="fpedidodetalleadd" class="ewForm form-horizontal" action="<?php echo ew_CurrentPage() ?>" method="post">
<input type="hidden" name="t" value="pedidodetalle">
<input type="hidden" name="a_add" id="a_add" value="A">
<table class="ewGrid"><tr><td>
<table id="tbl_pedidodetalleadd" class="table table-bordered table-striped">
<?php if ($pedidodetalle->detallePedido->Visible) { // detallePedido ?>
	<tr id="r_detallePedido">
		<td><span id="elh_pedidodetalle_detallePedido"><?php echo $pedidodetalle->detallePedido->FldCaption() ?></span></td>
		<td<?php echo $pedidodetalle->detallePedido->CellAttributes() ?>>
<?php if ($pedidodetalle->detallePedido->getSessionValue() <> "") { ?>
<span<?php echo $pedidodetalle->detallePedido->ViewAttributes() ?>>
<?php echo $pedidodetalle->detallePedido->ViewValue ?></span>
<input type="hidden" id="x_detallePedido" name="x_detallePedido" value="<?php echo ew_HtmlEncode($pedidodetalle->detallePedido->CurrentValue) ?>">
<?php } else { ?>
<input type="text" data-field="x_detallePedido" name="x_detallePedido" id="x_detallePedido" size="30" placeholder="<?php echo $pedidodetalle->detallePedido->PlaceHolder ?>" value="<?php echo $pedidodetalle->detallePedido->EditValue ?>"<?php echo $pedidodetalle->detallePedido->EditAttributes() ?>>
<?php } ?>
<?php echo $pedidodetalle->detallePedido->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($pedidodetalle->detalleItem->Visible) { // detalleItem ?>
	<tr id="r_detalleItem">
		<td><span id="elh_pedidodetalle_detalleItem"><?php echo $pedidodetalle->detalleItem->FldCaption() ?></span></td>
		<td<?php echo $pedidodetalle->detalleItem->CellAttributes() ?>>
<span id="el_pedidodetalle_detalleItem" class="control-group">
<input type="text" data-field="x_detalleItem" name="x_detalleItem" id="x_detalleItem" size="30" placeholder="<?php echo $pedidodetalle->detalleItem->PlaceHolder ?>" value="<?php echo $pedidodetalle->detalleItem->EditValue ?>"<?php echo $pedidodetalle->detalleItem->EditAttributes() ?>>
</span>
<?php echo $pedidodetalle->detalleItem->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($pedidodetalle->detalleProducto->Visible) { // detalleProducto ?>
	<tr id="r_detalleProducto">
		<td><span id="elh_pedidodetalle_detalleProducto"><?php echo $pedidodetalle->detalleProducto->FldCaption() ?></span></td>
		<td<?php echo $pedidodetalle->detalleProducto->CellAttributes() ?>>
<span id="el_pedidodetalle_detalleProducto" class="control-group">
<select data-field="x_detalleProducto" id="x_detalleProducto" name="x_detalleProducto"<?php echo $pedidodetalle->detalleProducto->EditAttributes() ?>>
<?php
if (is_array($pedidodetalle->detalleProducto->EditValue)) {
	$arwrk = $pedidodetalle->detalleProducto->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($pedidodetalle->detalleProducto->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
<?php if ($arwrk[$rowcntwrk][2] <> "") { ?>
<?php echo ew_ValueSeparator(1,$pedidodetalle->detalleProducto) ?><?php echo $arwrk[$rowcntwrk][2] ?>
<?php } ?>
</option>
<?php
	}
}
?>
</select>
<?php
$sSqlWrk = "SELECT `productosCodigo`, `productosCodigo` AS `DispFld`, `productosNombre` AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `productos`";
$sWhereWrk = "";

// Call Lookup selecting
$pedidodetalle->Lookup_Selecting($pedidodetalle->detalleProducto, $sWhereWrk);
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
?>
<input type="hidden" name="s_x_detalleProducto" id="s_x_detalleProducto" value="s=<?php echo ew_Encrypt($sSqlWrk) ?>&amp;f0=<?php echo ew_Encrypt("`productosCodigo` = {filter_value}"); ?>&amp;t0=3">
</span>
<?php echo $pedidodetalle->detalleProducto->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($pedidodetalle->detalleEstadoProducto->Visible) { // detalleEstadoProducto ?>
	<tr id="r_detalleEstadoProducto">
		<td><span id="elh_pedidodetalle_detalleEstadoProducto"><?php echo $pedidodetalle->detalleEstadoProducto->FldCaption() ?></span></td>
		<td<?php echo $pedidodetalle->detalleEstadoProducto->CellAttributes() ?>>
<span id="el_pedidodetalle_detalleEstadoProducto" class="control-group">
<select data-field="x_detalleEstadoProducto" id="x_detalleEstadoProducto" name="x_detalleEstadoProducto"<?php echo $pedidodetalle->detalleEstadoProducto->EditAttributes() ?>>
<?php
if (is_array($pedidodetalle->detalleEstadoProducto->EditValue)) {
	$arwrk = $pedidodetalle->detalleEstadoProducto->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($pedidodetalle->detalleEstadoProducto->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span>
<?php echo $pedidodetalle->detalleEstadoProducto->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($pedidodetalle->detalleUnidades->Visible) { // detalleUnidades ?>
	<tr id="r_detalleUnidades">
		<td><span id="elh_pedidodetalle_detalleUnidades"><?php echo $pedidodetalle->detalleUnidades->FldCaption() ?></span></td>
		<td<?php echo $pedidodetalle->detalleUnidades->CellAttributes() ?>>
<span id="el_pedidodetalle_detalleUnidades" class="control-group">
<input type="text" data-field="x_detalleUnidades" name="x_detalleUnidades" id="x_detalleUnidades" size="30" placeholder="<?php echo $pedidodetalle->detalleUnidades->PlaceHolder ?>" value="<?php echo $pedidodetalle->detalleUnidades->EditValue ?>"<?php echo $pedidodetalle->detalleUnidades->EditAttributes() ?>>
</span>
<?php echo $pedidodetalle->detalleUnidades->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($pedidodetalle->detalleMetros->Visible) { // detalleMetros ?>
	<tr id="r_detalleMetros">
		<td><span id="elh_pedidodetalle_detalleMetros"><?php echo $pedidodetalle->detalleMetros->FldCaption() ?></span></td>
		<td<?php echo $pedidodetalle->detalleMetros->CellAttributes() ?>>
<span id="el_pedidodetalle_detalleMetros" class="control-group">
<input type="text" data-field="x_detalleMetros" name="x_detalleMetros" id="x_detalleMetros" size="30" placeholder="<?php echo $pedidodetalle->detalleMetros->PlaceHolder ?>" value="<?php echo $pedidodetalle->detalleMetros->EditValue ?>"<?php echo $pedidodetalle->detalleMetros->EditAttributes() ?>>
</span>
<?php echo $pedidodetalle->detalleMetros->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($pedidodetalle->detallePallets->Visible) { // detallePallets ?>
	<tr id="r_detallePallets">
		<td><span id="elh_pedidodetalle_detallePallets"><?php echo $pedidodetalle->detallePallets->FldCaption() ?></span></td>
		<td<?php echo $pedidodetalle->detallePallets->CellAttributes() ?>>
<span id="el_pedidodetalle_detallePallets" class="control-group">
<input type="text" data-field="x_detallePallets" name="x_detallePallets" id="x_detallePallets" size="30" placeholder="<?php echo $pedidodetalle->detallePallets->PlaceHolder ?>" value="<?php echo $pedidodetalle->detallePallets->EditValue ?>"<?php echo $pedidodetalle->detallePallets->EditAttributes() ?>>
</span>
<?php echo $pedidodetalle->detallePallets->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($pedidodetalle->detallePaquetes->Visible) { // detallePaquetes ?>
	<tr id="r_detallePaquetes">
		<td><span id="elh_pedidodetalle_detallePaquetes"><?php echo $pedidodetalle->detallePaquetes->FldCaption() ?></span></td>
		<td<?php echo $pedidodetalle->detallePaquetes->CellAttributes() ?>>
<span id="el_pedidodetalle_detallePaquetes" class="control-group">
<input type="text" data-field="x_detallePaquetes" name="x_detallePaquetes" id="x_detallePaquetes" size="30" placeholder="<?php echo $pedidodetalle->detallePaquetes->PlaceHolder ?>" value="<?php echo $pedidodetalle->detallePaquetes->EditValue ?>"<?php echo $pedidodetalle->detallePaquetes->EditAttributes() ?>>
</span>
<?php echo $pedidodetalle->detallePaquetes->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($pedidodetalle->detallePreparado->Visible) { // detallePreparado ?>
	<tr id="r_detallePreparado">
		<td><span id="elh_pedidodetalle_detallePreparado"><?php echo $pedidodetalle->detallePreparado->FldCaption() ?></span></td>
		<td<?php echo $pedidodetalle->detallePreparado->CellAttributes() ?>>
<span id="el_pedidodetalle_detallePreparado" class="control-group">
<input type="text" data-field="x_detallePreparado" name="x_detallePreparado" id="x_detallePreparado" size="30" placeholder="<?php echo $pedidodetalle->detallePreparado->PlaceHolder ?>" value="<?php echo $pedidodetalle->detallePreparado->EditValue ?>"<?php echo $pedidodetalle->detallePreparado->EditAttributes() ?>>
</span>
<?php echo $pedidodetalle->detallePreparado->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($pedidodetalle->detalleMotivo->Visible) { // detalleMotivo ?>
	<tr id="r_detalleMotivo">
		<td><span id="elh_pedidodetalle_detalleMotivo"><?php echo $pedidodetalle->detalleMotivo->FldCaption() ?></span></td>
		<td<?php echo $pedidodetalle->detalleMotivo->CellAttributes() ?>>
<span id="el_pedidodetalle_detalleMotivo" class="control-group">
<select data-field="x_detalleMotivo" id="x_detalleMotivo" name="x_detalleMotivo"<?php echo $pedidodetalle->detalleMotivo->EditAttributes() ?>>
<?php
if (is_array($pedidodetalle->detalleMotivo->EditValue)) {
	$arwrk = $pedidodetalle->detalleMotivo->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($pedidodetalle->detalleMotivo->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
<?php
$sSqlWrk = "SELECT `motivoId`, `motivoNombre` AS `DispFld`, '' AS `Disp2Fld`, '' AS `Disp3Fld`, '' AS `Disp4Fld` FROM `motivos`";
$sWhereWrk = "";

// Call Lookup selecting
$pedidodetalle->Lookup_Selecting($pedidodetalle->detalleMotivo, $sWhereWrk);
if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
?>
<input type="hidden" name="s_x_detalleMotivo" id="s_x_detalleMotivo" value="s=<?php echo ew_Encrypt($sSqlWrk) ?>&amp;f0=<?php echo ew_Encrypt("`motivoId` = {filter_value}"); ?>&amp;t0=3">
</span>
<?php echo $pedidodetalle->detalleMotivo->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($pedidodetalle->detalleTipo->Visible) { // detalleTipo ?>
	<tr id="r_detalleTipo">
		<td><span id="elh_pedidodetalle_detalleTipo"><?php echo $pedidodetalle->detalleTipo->FldCaption() ?></span></td>
		<td<?php echo $pedidodetalle->detalleTipo->CellAttributes() ?>>
<span id="el_pedidodetalle_detalleTipo" class="control-group">
<input type="text" data-field="x_detalleTipo" name="x_detalleTipo" id="x_detalleTipo" size="30" maxlength="1" placeholder="<?php echo $pedidodetalle->detalleTipo->PlaceHolder ?>" value="<?php echo $pedidodetalle->detalleTipo->EditValue ?>"<?php echo $pedidodetalle->detalleTipo->EditAttributes() ?>>
</span>
<?php echo $pedidodetalle->detalleTipo->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($pedidodetalle->detallePunto->Visible) { // detallePunto ?>
	<tr id="r_detallePunto">
		<td><span id="elh_pedidodetalle_detallePunto"><?php echo $pedidodetalle->detallePunto->FldCaption() ?></span></td>
		<td<?php echo $pedidodetalle->detallePunto->CellAttributes() ?>>
<span id="el_pedidodetalle_detallePunto" class="control-group">
<input type="text" data-field="x_detallePunto" name="x_detallePunto" id="x_detallePunto" size="30" placeholder="<?php echo $pedidodetalle->detallePunto->PlaceHolder ?>" value="<?php echo $pedidodetalle->detallePunto->EditValue ?>"<?php echo $pedidodetalle->detallePunto->EditAttributes() ?>>
</span>
<?php echo $pedidodetalle->detallePunto->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($pedidodetalle->detalleNumero->Visible) { // detalleNumero ?>
	<tr id="r_detalleNumero">
		<td><span id="elh_pedidodetalle_detalleNumero"><?php echo $pedidodetalle->detalleNumero->FldCaption() ?></span></td>
		<td<?php echo $pedidodetalle->detalleNumero->CellAttributes() ?>>
<span id="el_pedidodetalle_detalleNumero" class="control-group">
<input type="text" data-field="x_detalleNumero" name="x_detalleNumero" id="x_detalleNumero" size="30" placeholder="<?php echo $pedidodetalle->detalleNumero->PlaceHolder ?>" value="<?php echo $pedidodetalle->detalleNumero->EditValue ?>"<?php echo $pedidodetalle->detalleNumero->EditAttributes() ?>>
</span>
<?php echo $pedidodetalle->detalleNumero->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</td></tr></table>
<button class="btn btn-primary ewButton" name="btnAction" id="btnAction" type="submit"><?php echo $Language->Phrase("AddBtn") ?></button>
</form>
<script type="text/javascript">
fpedidodetalleadd.Init();
<?php if (EW_MOBILE_REFLOW && ew_IsMobile()) { ?>
ew_Reflow();
<?php } ?>
</script>
<?php
$pedidodetalle_add->ShowPageFooter();
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
?>
<script type="text/javascript">

// Write your table-specific startup script here
// document.write("page loaded");

</script>
<?php include_once "footer.php" ?>
<?php
$pedidodetalle_add->Page_Terminate();
?>
